<?php

namespace app\api\validate;

use think\Validate;

class Manager extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'mg_name|用户名'       =>    'require|chsDash|unique:manager',
        'mg_pwd|密码'          =>    'require|min:6',
        'mg_email|邮箱'        =>    'require|email|unique:manager',
        'mg_mobile|手机号'     =>    'require|/^[1][3,4,5,7,8][0-9]{9}$/|unique:manager',
        'role_id|角色id'       =>    'require'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [];

    protected $scene = [
        'role'  =>  ['role_id']
    ];

    //登录验证
    public function sceneLogin()
    {
        return $this->only(['mg_name','mg_pwd'])
            ->remove('mg_name','unique|chsDash')
            ->remove('mg_pwd','min');
    }
    //新增用户验证
    public function sceneSave()
    {
        return $this->only(['mg_name','mg_pwd','mg_email','mg_mobile']);
    }
    //编辑用户提交
    public function sceneUpdate()
    {
        return $this->only(['mg_email','mg_mobile'])
                   ->remove('mg_email','unique')
                   ->remove('mg_mobile','unique');
    }
}
